package com.atguigu.gulimall.vo;

import lombok.Data;

import java.math.BigDecimal;
import java.util.List;

// 需要计算的属性我们重写 get 方法，保证每次获取属性都会重新计算
public class Cart {

    private List<CartItem> items;

//    public void setCountNum(Integer countNum) {
//        this.countNum = countNum;
//    }
//
//    public void setCountType(Integer countType) {
//        this.countType = countType;
//    }
//
//    public void setTotalAmount(BigDecimal totalAmount) {
//        this.totalAmount = totalAmount;
//    }

    private Integer countNum; // 商品数量

    private Integer countType; // 商品类型属性

    private BigDecimal totalAmount; // 商品总价

    private BigDecimal reduce = new BigDecimal("0"); // 减免价格

    public List<CartItem> getItems() {
        return items;
    }

    public void setItems(List<CartItem> items) {
        this.items = items;
    }

    public Integer getCountNum() {
        int count = 0;
        for (CartItem item : items) {
            count += item.getCount();
        }
        return count;
    }


    public Integer getCountType() {
        return items.size();
    }


    public BigDecimal getTotalAmount() {
        BigDecimal amount = new BigDecimal("0");
        for (CartItem item : items) {
            if (item.getCheck()) {
                BigDecimal totalPrice = item.getTotalPrice();
                amount = amount.add(item.getTotalPrice());
            }
        }
        System.out.println(amount);
        amount = amount.subtract(this.reduce);
        return amount;
    }


    public BigDecimal getReduce() {
        return reduce;
    }

    public void setReduce(BigDecimal reduce) {
        this.reduce = reduce;
    }
}
